package com.lynn.lib_base.http.interceptor

import com.lynn.lib_base.http.listener.IGetAppInfo
import com.lynn.common.utils.date.DateTimeUtil
import okhttp3.Interceptor
import okhttp3.Response

/**
 * @description: 请求拦截器
 * @author: bailing
 * @datetime: 2025/5/27 14:30
 **/
class RequestInterceptor(val listener: IGetAppInfo) : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val nowDateTime = DateTimeUtil.getDateTime()

        //构建器
        val request = chain.request().newBuilder()
            //添加使用环境
            .addHeader("os", "android")
            //添加版本号
            .addHeader("appVersionCode", this.listener.getAppVersionCode())
            //添加版本名
            .addHeader("appVersionName", this.listener.getAppVersionName())
            //添加日期时间
            .addHeader("datetime", nowDateTime)
            .build()

        //返回
        return chain.proceed(request)
    }
}